import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();
        String s = scanner.nextLine();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = scanner.nextInt();
        }

        Solution solution = new Solution();
        System.out.println(solution.minCost(s, array));

    }
}

class Solution {
    public int minCost(String colors, int[] neededTime) {
        int n = neededTime.length;
        int res = 0;
        int maxT = 0;
        char[] arr = colors.toCharArray();
        for (int i = 0; i < n; i++) {
            int t = neededTime[i];
            res += t;
            maxT = Math.max(maxT, t);
            if (i == n - 1 || arr[i] != arr[i + 1]) {
                res -= maxT;
                maxT = 0;
            }
        }
        return res;
    }
}
